<?php




class XgnCore{

	public static $Area;

	public function __construct(){

	}



	public function run(){
		spl_autoload_register(array($this, 'loadClass'),false);
		$this->call();
	}


	public function call(){
		if(empty($_GET['area']) or empty($_GET['controller']) or empty($_GET['action'])){
			//非法的URL
			die('illegal Url');
		}

		//路由
		self::$Area=$_GET['area'];

		$controller=$_GET['controller'].'Controller';
		$action=$_GET['action'];

		$cobj=new $controller();

		if(method_exists($cobj, $action)==True){
			define("AREA_PATH",APP_PATH.XgnCore::$Area.DIRECTORY_SEPARATOR);

			//调用控制器
			call_user_func_array(array($cobj,$action),array());
		}else{
			die($controller.'控制器不存在');
		}

	}

	public static function loadClass($classname){
		#加载框架核心类
		require_once(ROOT.'XgnController'.EXT);

		#加载控制器
		$path= APP_PATH.XgnCore::$Area.DIRECTORY_SEPARATOR.'controllers'.DIRECTORY_SEPARATOR.$classname.EXT;
		require_once($path);
	}
}
